package com.juneng.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.juneng.constant.Constant;

/**
 * 分页工具
 *
 * @author 吴昊
 */
public class 	Condition {

	/**
	 * 转化成mybatis plus中的Page
	 *
	 * @param query
	 * @return
	 */
	public static <T> IPage<T> getPage(CommonDto commonDto) {
		if (commonDto.getPageSize() > Constant.PAGE_MAX_SIZE) {
			commonDto.setPageSize(Constant.PAGE_MAX_SIZE);
		}
		return new Page<>(commonDto.getPageNum(), commonDto.getPageSize());
	}

	/**
	 * 转化成mybatis plus中的Page
	 *
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public static <T> IPage<T> getPage(Integer pageNum, Integer pageSize) {
		if (pageSize > Constant.PAGE_MAX_SIZE) {
			pageSize = Constant.PAGE_MAX_SIZE;
		}
		return new Page<>(pageNum, pageSize);
	}

	/**
	 * 获取mybatis plus中的QueryWrapper
	 *
	 * @param entity
	 * @param <T>
	 * @return
	 */
	public static <T> QueryWrapper<T> getQueryWrapper(T entity) {
		return new QueryWrapper<>(entity);
	}

	/**
	 * 获取mybatis plus中的QueryWrapper
	 *
	 * @param QueryWrapper<T>
	 * @return
	 */
	public static <T> QueryWrapper<T> getQueryWrapper() {
		return new QueryWrapper<>();
	}

}
